<template>
	<view class="goods_list">
		<goods-list @clickItem="goGoodsDetail" :goods="goods"></goods-list>
		<view class="isover" v-if="isover">
			---下面没有内容了！---
		</view>
	</view>
</template>

<script>
	import goodsList from '@/components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				goods: [],
				pageIndex: 1,
				isover: false
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		methods: {
			// 获取商品列表数据
			async getGoodsList() {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.pageIndex
				})
				// console.log(res)
				this.goods = [...this.goods, ...res.data.message]
			},
			// 导航到商品详情页
			goGoodsDetail(id) {
				uni.navigateTo({
					url: '/pages/goods-detail/goods-detail?id='+id
				})
			}
		},
		components: {
			goodsList
		},
		onReachBottom() {
			if(this.goods.length < this.pageIndex*10) return this.isover = true
			this.pageIndex++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.pageIndex = 1
			this.isover = false
			this.goods = []
			setTimeout(() => {
				this.getGoodsList()
				uni.stopPullDownRefresh()
			}, 1000)
		}
	}
</script>

<style lang="scss">
 .goods_list {
	 background-color: #ccc;
 }
 .isover {
	 width: 750rpx;
	 height: 100rpx;
	 text-align: center;
	 line-height: 100rpx;
 }
</style>
